
/*
 *
 * Copyright (C) 2008 Mattias Blomqvist, patr-blo at dsv dot su dot se
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using System.IO;
using ClientExample.Containers;

namespace ClientExample.Controls
{
    public partial class HardDriveInfo : UserControl
    {
        protected DriveInfo drive = null;
        protected int procentage = 0;
        protected Color color = Color.Blue;

        public HardDriveInfo()
        {
			IntPtr h = Handle;  // This is for stupid mono stuff. Some how handle isnt created correctly if we dont do this :(
            InitializeComponent();
        }

        public DriveInfo DriveInfo
        {
            get { return drive; }
            set
            {
                if (value == null)
                    return;
                drive = value;
                label1.Text = drive.Name;
                try
                {
                    progressBar1.Maximum = 100;
                    procentage = (int)(((double)drive.TotalFreeSpace / (double)drive.TotalSize) * 100);
                    if (procentage < 5)
                    {
                        color = Color.Red;
                    }
                    else if (procentage < 15)
                    {
                        color = Color.Orange;
                    }
                    else if (procentage < 20)
                    {
                        color = Color.Yellow;
                    }
                    else if (procentage < 25)
                    {
                        color = Color.YellowGreen;
                    }
                    else if (procentage < 30)
                    {
                        color = Color.Green;
                    }
                    progressBar1.Value = 100 - procentage;
                }
                catch
                {
                    color = Color.Gray;
                }
            }
        }

        private void HardDriveInfo_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = Program.Images.GetBitmap("drive.gif");
        }
    }
}
